home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-17 | 47.4 KB | 1,261 lines | [TEXT/MPS ] |
- #
- # ****************************************************************************
- #
- # File Name: Draw.Lib
- #
- # Contains: Tasks to help do testing of drawing operations
- #
- # Written by: Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
- #
- # Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
- #
- # ****************************************************************************
- # C h a n g e H i s t o r y (most recent first):
- # ****************************************************************************
- #
- # Vers Date Author Description
- # ---- -------- ------ ---------------------------------------------
- # <1.0.10> 12/2/93 KTA CheckObjectStruct() doesn't choke on kMultiClickDrag tools
- # anymore.
- # <1.0.9> 11/19/93 NAGA Modify TCS format
- # <1.0.8> 8/30/93 KTA Updated task headers and parameters.
- # <1.0.7> 8/25/93 KTA Added support for parity checking the TCS stack.
- # <1.0.6> 8/3/93 KTA DrawObject()- Fixed bug where directCoord Tools weren't setting
- # any attributes.
- # <1.0.4> 6/8/93 NAGA unmark tasks that are not published
- # <2+> 6/8/93 NAGA unmark tasks that are not published
- # <1+> 5/21/93 NAGA Adding header and porting old files to follow new standards
- #
- # ****************************************************************************
- #
-
- ########################################################################
- # External libraries
- #=======================================================================
- Libraries "Palette.Lib", "String.Lib","OutPut.lib", "TCS.Lib", "Geometry.Lib","UserInterface.Lib";
-
- #########################################################################
- # InitDraw()
- #========================================================================
- # Author: KTA
- # Description: Initializes the Draw globals.
- # Parameters: None
- # Returns: Nada
- # Examples: InitDraw();
- # Assumptions:
- #========================================================================
- # History:
- #
- #########################################################################
- TASK InitDraw()
- begin
- ############## Task References ############
- global gSetLine := Task SetLine; # Requires VU 2.0
- global gSetColor := Task SetColor; # Requires VU 2.0
- global gSetPattern := Task SetPattern; # Requires VU 2.0
-
- ############## Tool Type Defines ############
- global kClick := 1;
- global kDrag := 2;
- global kDragClick := 3;
- global kMultiDrag := 4;
- global kMultiClick := 5;
- global kMultiClickDrag := 6;
-
- ############## Palette Type Defines ########
- global kPalDocWind := 1;
- global kPalWind := 2;
- global kPopUpPal := 3;
-
- ############## Script Contants ############
- global gWindowInset := {0,20,20,20}; # Inset to wind to get content region
- global gScreenInset := {0,20,0,0}; # Inset to screen
- global gBoundingRect := {}; #
- global gVoidRect := {}; # Rect not to draw in - coordinates should be RelativeToWindow
- global gLineWeights := {}; # Line Weights
- global gNumPoints := 6; # Number of points for all multipoint tools
- global gDrawObject := 0; # Object Number in a given suite (incremented by DrawObject)
- end;
-
- #########################################################################
- # CheckObjectStruct(pObjectStruct)
- #========================================================================
- # Author: Kevin Avoy
- # Description: Check validity of elements in pObjectStruct.
- # Parameters: pObjectStruct - the objectStruct to check
- # Returns: 0 - objectStruct is hosed
- # 1 - objectStruct is OK
- # Example: returnVal := CheckObjectStruct(pObjectStruct);
- #========================================================================
- # History:
- # KTA 12/01/93 kMultiClickDrag tools weren't supported added
- # elemType <= 6 (bug #1117685)
- #########################################################################
- TASK CheckObjectStruct(pObjectStruct)
- begin
- if (global gDebugFlag)
- println "----- CheckObjectStruct() - Draw.lib --------";
- global gNumPoints;
- returnVal := 1;
-
- if not(Card(pObjectStruct) = 5)
- begin
- Println "!@#$% CheckObjectFailure - Card(pObjectStruct) - ", Card(pObjectStruct);
- returnVal := 0;
- end;
-
- ## Tool Struct
- elemStruct := GetElemStruct(pObjectStruct);
- if not(Card(elemStruct) = 6)
- begin
- Println "!@#$% CheckObjectFailure - Card(elemStruct) - ", Card(elemStruct);
- returnVal := 0;
- end;
-
- ## ToolType
- elemType := GetElemType(elemStruct);
- if not (elemStruct = 'Random')
- begin
- if not((elemType >= 0) and (elemType <= 6) )
- begin
- Println "!@#$% CheckObjectFailure - elemType - ", ElemType;
- returnVal := 0;
- end;
- end;
-
- ## Tool Name
- elemName := GetElemName(elemStruct);
- if not (elemStruct = 'Random')
- begin
- if not( TypeOf(elemName) = "string" )
- begin
- Println "!@#$% CheckObjectFailure - elemName - ", elemName;
- returnVal := 0;
- end;
- end;
-
- ## DoubleClick
- elemDblClk := GetElemDblClk(elemStruct);
- if not (elemStruct = 'Random')
- begin
- if not((elemDblClk = 0) or (elemDblClk = 1) )
- begin
- Println "!@#$% CheckObjectFailure - elemDblClk - ", elemDblClk;
- returnVal := 0;
- end;
- end;
-
- ## Pointlist
- pointList := GetPointList(pObjectStruct);
- if (global gDebugFlag)
- println "This is the pointlist",pointList;
- (*
- if not((Card(pointList) = gNumPoints) or (Card(pointList) = elemType))
- begin
- Println "!@#$% CheckObjectFailure - pointList - ", pointList;
- returnVal := 0;
- end;
-
- ## Line
- theLine := GetLine(pObjectStruct);
- if not((TypeOF(theLine) = "list") and (Card(theLine) = 3) or (theLine = 0))
- begin
- Println "!@#$% CheckObjectFailure - theLine - ", theLine;
- returnVal := 0;
- end;
-
- ## Color
- theCol := GetColor(pObjectStruct);
- if not((TypeOF(theCol) = "list") and (Card(theCol) = 3) or (theCol = 0))
- begin
- Println "!@#$% CheckObjectFailure - theCol - ", theCol;
- returnVal := 0;
- end;
-
- ## Pattern
- thePat := GetPattern(pObjectStruct);
- if not((TypeOF(thePat) = "list") and (Card(thePat) = 3) or (thePat = 0))
- begin
- Println "!@#$% CheckObjectFailure - thePat - ", thePat;
- returnVal := 0;
- end;
- *)
- if (global gDebugFlag) # Set gDebugFlag to TRUE to output variables for debugging
- begin
- Println "======= DebugStr - CheckObject() in Draw.Lib ======";
- Println " pObjectStruct - ", {pObjectStruct};
- Println " elemStruct - ", {elemStruct};
- Println " elemType - ", {elemType};
- Println " elemName - ", {elemName};
- Println " elemDblClk - ", {elemDblClk};
- Println " pointList - ", {pointList};
- end;
-
- return returnVal;
- end; # CheckObjectStruct()
-
- #########################################################################
- # DrawObject(pObjectStruct, pSpecifier)
- #========================================================================
- # Author: David Matzner / Kevin Avoy
- # Description: Main routine in the Draw Libraries. Calls all subroutines
- # necessary to draw a given object, passing the appropriate
- # elements from the pObjectStruct input param.
- # Parameters: pObjectStruct := {
- # {ToolStruct},
- # {PointList},
- # {PatternStruct},
- # {LineStruct},
- # {ColorStruct}
- # };
- # pSpecifier - Specifies the window (or Rect) to draw in)
- # Returns: 1 - exercises went OK
- # 0 - error in drawing object
- # Examples: noError := DrawObject(objectStruct,specifier);
- # DrawObject({global SelectTool, {{25,15}}, {12,2 ,’Pattern’}, 0, ‘Random’});
- #========================================================================
- # History:
- # KTA 8/3/92 Fixed bug where directCoord Tools weren't setting any attributes
- #########################################################################
- TASK DrawObject(pObjectStruct := {}, pSpecifier := 0) begin
- global kClick, kDrag,kDragClick, kMultiDrag, kMultiClickDrag, kMultiClick,gToolsThatUseLineWeight, gDrawObject;
- gDrawObject := gDrawObject + 1; # Increment the object number for TCS info
- TempMouse := MouseSpeed(5);
- TempTargetCheck := global gTargetCheck;
- global gTargetCheck := 0;
- if (global gDebugFlag)
- println "----- DrawObject() - Draw.lib --------";
-
- ## Call accessors to access object struct
- ToolStruct := GetElemStruct(pObjectStruct);
- if (ToolStruct = 'Random')
- begin
- pObjectStruct := InsertElemStruct(SetTool(ToolStruct,0),pObjectStruct); # insert a random one but don't select it.
- ToolStruct := GetElemStruct(pObjectStruct);
- if (global gDebugFlag)
- println "----- This is the ObjectStruct after inserting Toolstruct -", pObjectStruct;
- end;
- elemPalNum := GetPalNum(ToolStruct);
- elemType := GetElemType(ToolStruct);
- elemName := GetElemName(ToolStruct);
- elemDblClk := GetElemDblClk(ToolStruct);
- elemNum := GetElemNum(ToolStruct);
- SetAttributeFlag := GetSetAttribute(ToolStruct);
-
- pointList := SetPointList(pObjectStruct, pSpecifier);
- pObjectStruct := InsertPointList(pointList, pObjectStruct);
-
- returnVal := CheckObjectStruct(pObjectStruct); #
- if (returnVal)
- begin
- if (TypeOf(elemPalNum) = 'list') ## Handle Coordinate tools
- returnVal := PalettePicker(ToolStruct);
- else
- SetTool(ToolStruct,,gDrawObject);
- ###########################################################
- #### Call to set object attributes and update pObjectStruct
- ###########################################################
- if(not(SetAttributeFlag) or ((Typeof(SetAttributeFlag) = 'string') and (Card(GetAttributes(ToolStruct)) = 1)))
- begin
- pObjectStruct := InsertPattern(0, pObjectStruct) ;# Insert NIL patternStruct
- pObjectStruct := InsertColor(0, pObjectStruct) ;# Insert NIL ColorStruct
- pObjectStruct := InsertLine(0, pObjectStruct) ;# Insert NIL LineStruct
- end;
- else if(SetAttributeFlag = 1)
- pObjectStruct := SetAttributes(pObjectStruct,gDrawObject);
-
- if(elemType) # Tool Type is zero because we don't want to draw an object
- begin
- # inform the user of the object we are going to draw
- pointStr := PointListToStr(pointList); # put pointList into a string
- str := "-- Drawing object defined by points {pointStr}";
- if (elemType = kClick)
- LogStr(Str);
- else
- begin
- # inform user of actions to take place before/during/after each move
- if ((elemType = kDrag) or (elemType = kMultiDrag))
- LogStr("{str} Will hold mouse down during move");
- else if (elemType = kMultiClickDrag)
- LogStr("{str} Will hold mouse down during each move and release at each destination point");
- else if (elemType = kMultiClick)
- LogStr("{str} Will click at each point");
- end;
-
- temp := global gDisableAllLogging;
- if not(global gDebugFlag)
- gDisableAllLogging := 1;
-
- # Call the UseTool Routines
- thePt := pointList[1]; # get first point
- MoveRelativeToWindow(thePt[1],thePt[2],pSpecifier); # move to the first point and set relativeFlag
- pointList := remove(1,pointList); # remove first point from list - we already used it
- if (elemType = kClick)
- returnVal := UseClickTool();
- else if (elemType = kDrag)
- returnVal := UseDragTool( pointList[1], pSpecifier, ,elemDblClk );
- else if (elemType = kDragClick)
- returnVal := UseDragClickTool( pointList, pSpecifier, ,elemDblClk );
- else if (elemType = kMultiDrag)
- returnVal := UseMultiDragTool( pointList, pSpecifier, elemDblClk );
- else if (elemType = kMultiClick)
- returnVal := UseMultiClickTool( pointList, pSpecifier, elemDblClk );
- else if (elemType = kMultiClickDrag)
- returnVal := UseMultiClickDragTool( pointList, pSpecifier, elemDblClk );
- else begin
- LogStr("No tool function declared for tool type {elemType}");
- returnVal := 0;
- end;
- gDisableAllLogging := temp;
- end;
- else
- Println "Tool Type for this tool is 0, so no object drawn.";
-
- if (DialogCheck('',1)) # Check for any dialogs
- returnVal := 0;
- if (returnVal)
- begin
- if(SetAttributeFlag = 2) or (Typeof(SetAttributeFlag) = 'string')
- pObjectStruct := SetAttributes(pObjectStruct,gDrawObject);
- ### To handle text entry
- if(Typeof(SetAttributeFlag) = 'string')
- TypeStr(SetAttributeFlag);
-
- if (returnVal)
- begin
- LogStr("----- Finished drawing object -----");
- returnVal := pObjectStruct;
- end;
- end;
- else
- LogStr("!@#$% Failed to draw object !@#$%");
- end;
- Println "• theObject - ", returnVal;
- println "-----------------------------------";
- println ;
- MouseSpeed(TempMouse);
- gTargetCheck := TempTargetCheck;
- return(returnVal);
- end; # DrawObject()
-
- #########################################################################
- # SetAttributes(pObjectStruct,pDrawObject)
- #========================================================================
- # Author: Kevin Avoy
- # Description: This task takes a complete objectStruct as a parameter, it will
- # determine if the tool being used to draw with can set various
- # attributes (patterns, lines, and colors). If so the appropriate
- # tasks will be called and the actual attribute structs used will
- # be inserted into the objectStruct prior to returning.
- # Parameters: pObjectStruct - a complete objectStruct - note some elements will
- # evaluate to 0 or random upon entry - the random
- # elements will be replaced with actual atribute
- # struct prior to exiting. Elements that are 0 will
- # not be set.
- # pDrawObject - This is the number that is used to tie together
- # all elements that make up an object for TCS
- # logging purposes.
- # Returns: pObjectStruct - Setting attributes went OK
- # 0 - error in - Setting attributes
- # Examples:
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SetAttributes(pObjectStruct,pDrawObject)
- begin
- global gSetPattern, gSetLine, gSetColor;
- elemStruct := GetElemStruct(pObjectStruct);
- elemNum := GetElemNum(ElemStruct);
- ###########################################################
- #### Call to set object attributes and update pObjectStruct
- ###########################################################
- ##### SetPattern ######
- if(GetPatternFlag(elemStruct))
- begin
- thePat := GetPattern(pObjectStruct);
- if (thePat)
- begin
- myPat := Call(gSetPattern, thePat,,pDrawObject);
- pObjectStruct := InsertPattern(myPat, pObjectStruct);
- end;
- if (global gDebugFlag)
- println "This is the pObjectStruct after SetPattern - ", pObjectStruct;
- end;
- else
- begin
- if (global gDebugFlag)
- LogStr("This is not a pattern tool");
- pObjectStruct := InsertPattern(0, pObjectStruct);
- end;
- ##### SetLine ######
- if(GetLineFlag(elemStruct))
- begin
- theLine := GetLine(pObjectStruct);
- if (theLine)
- begin
- myLine := Call(gSetLine, theLine,,pDrawObject);
- pObjectStruct := InsertLine(myLine, pObjectStruct);
- end;
- if (global gDebugFlag)
- println "This is the pObjectStruct after SetLine - ", pObjectStruct;
- end;
- else
- begin
- if (global gDebugFlag)
- LogStr("This is not a tool that supports different line weights");
- pObjectStruct := InsertLine(0, pObjectStruct);
- end;
-
- ##### SetColor ######
- if(GetColorFlag(elemStruct))
- begin
- theCol := GetColor(pObjectStruct);
- if(theCol)
- begin
- theColor := Call(gSetColor, theCol,,pDrawObject);
- pObjectStruct := InsertColor(theColor,pObjectStruct); #
- #pObjectStruct := InsertColor(SetColor(theCol),pObjectStruct); # VU 1.1 call
- end;
- if (global gDebugFlag)
- println "This is the pObjectStruct after SetColor - ", pObjectStruct;
- end;
- else
- begin
- if (global gDebugFlag)
- LogStr("This is not a color tool");
- pObjectStruct := InsertColor(0, pObjectStruct);
- end;
-
- return(pObjectStruct);
- end; # SetAttributes()
-
- #########################################################################
- # UseClickTool()
- #========================================================================
- # Author: David Matzner (x41220)
- # Description: Click once at the current mouse location.
- # Parameters: None
- # Returns: 1 - Clicked
- # Examples: UseClickTool();
- # Assumptions: None
- #========================================================================
- # History:
- #
- #########################################################################
- TASK UseClickTool() begin
- if (global gDebugFlag)
- println "----- UseClickTool() - Draw.lib --------";
-
- click; # already at first point - do first click
- LogStr("Clicked the mouse button");
- return(1);
- end;
-
- #########################################################################
- # UseDragTool(pPoint, pSpecifier, pMouseDown, pDClickToEnd)
- #========================================================================
- # Author: David Matzner (x41220)
- # Description: Drag from the current location.
- # Parameters: pPoint - Point to move to.
- # pSpecifier - Window specifier in which to drag in.
- # pMouseDown - 0 - don't hold mouse key down while moving
- # 1 - press mouse key down - move - release
- # 2 - Click after moving - no mouse down during move
- # 3 - press mouse key down - move - don't release
- # 4 - move - release
- # pDClickToEnd - Boolean flag indicating whether or not to double
- # click the mouse after dragging.
- # Returns: returnVal - what moveRelativeToWindow returns.
- # Examples: UseDragTool({100,200}, 0, 1,0);
- # Assumptions: Mouse positioned at start point on entry. All points are
- # specified relative to window.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK UseDragTool(pPoint:= {}, pSpecifier := 0, pMouseDown := 1, pDClickToEnd := 0)
- begin
- if (global gDebugFlag)
- println "----- UseDragTool() - Draw.lib --------";
- returnVal := 0;
- h := pPoint[1];
- v := pPoint[2];
- if (global gDebugFlag)
- Println "Using the drag tool, {h}, {v}";
- returnVal := MoveRelativeToWindow( h , v , pSpecifier, pMouseDown);
- if (pDClickToEnd) begin # doubleClick to end sequence
- doubleClick;
- #LogStr("Double-clicked the mouse button to end drawing sequence");
- end;
-
- return(returnVal);
- end;
-
- #########################################################################
- # UseDragClickTool(pPointList, pSpecifier, pMouseDown, pDClickToEnd)
- #========================================================================
- # Author: Kevin Avoy (x45604)
- # Description: Drag from the current location. Then click at a different point.
- # Parameters: pPointList - List of points to move to.
- # pSpecifier - Window specifier in which to drag in.
- # pMouseDown - 0 - don't hold mouse key down while moving
- # 1 - press mouse key down - move - release
- # 2 - Click after moving - no mouse down during move
- # 3 - press mouse key down - move - don't release
- # 4 - move - release
- # pDClickToEnd - Boolean flag indicating whether or not to double
- # click the mouse after dragging.
- # Returns: returnVal - what MoveRelativeToWindow returns.
- # Examples: UseDragClickTool({{100,200}, {200,300}},0,1,0);
- # Assumptions: Mouse positioned at start point on entry. All points are
- # specified relative to window.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK UseDragClickTool(pPointList:= {}, pSpecifier := 0, pMouseDown := 1, pDClickToEnd := 0)
- begin
- if (global gDebugFlag)
- begin
- println "----- UseDragClickTool() - Draw.lib --------";
- println "pPointList - ", pPointList;
- end;
- returnVal := 0;
- dragPt := pPointList[1];
- clickPt := pPointList[2];
-
- dragH := dragPt[1];
- dragV := dragPt[2];
- clickH := clickPt[1];
- clickV := clickPt[2];
- if (global gDebugFlag)
- Println "Using the dragClick tool";
- returnVal := MoveRelativeToWindow( dragH , dragV , pSpecifier, pMouseDown);
- returnVal := MoveRelativeToWindow( clickH ,clickV , pSpecifier, 2);
- if (pDClickToEnd)
- begin # doubleClick to end sequence
- doubleClick;
- #LogStr("Double-clicked the mouse button to end drawing sequence");
- end;
-
- return(returnVal);
- end; # UseDragClickTool()
-
- #########################################################################
- # UseMultiDragTool(pPointList, pSpecifier, pDClickToEnd)
- #========================================================================
- # Author: David Matzner (x41220)
- # Description: mouseDown-drag-drag-drag-drag-release.
- # Parameters: pPointList - List of points to move to.
- # pSpecifier - Window specifier in which to drag in.
- # pDClickToEnd - Boolean flag indicating whether or not to double
- # click the mouse after dragging.
- # Returns: returnVal - what MoveRelativeToWindow returns.
- # Examples: UseMultiDragTool({{100,200}, {200,300}},0,0);
- # Assumptions: Mouse positioned at start point on entry. All points are
- # specified relative to window.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK UseMultiDragTool(pPointList := {}, pSpecifier := 0, pDClickToEnd := 0)
- begin
- if (global gDebugFlag)
- println "----- UseMultiDragTool() - Draw.lib --------";
- returnVal := MoveRelativeToWindow( pPointList ,, pSpecifier,3);
- if (pDClickToEnd)
- begin # doubleClick to end sequence
- doubleClick;
- #LogStr("Double-clicked the mouse button to end drawing sequence");
- end;
-
- return(returnVal);
- end;
-
- #########################################################################
- # UseMultiClickTool(pPointList, pSpecifier, pDClickToEnd)
- #========================================================================
- # Author: David Matzner (x41220)
- # Description: click-move-click-move….
- # Parameters: pPointList - List of points to move to.
- # pSpecifier - Window specifier in which to drag in.
- # pDClickToEnd - Boolean flag indicating whether or not to double
- # click the mouse after dragging.
- # Returns: returnVal - what MoveRelativeToWindow returns.
- # Examples: UseMultiClickTool({{100,200}, {200,300}},0,0);
- # Assumptions: Mouse positioned at start point on entry. All points are
- # specified relative to window.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK UseMultiClickTool(pPointList, pSpecifier := 0, pDClickToEnd := 0)
- begin
- if (global gDebugFlag)
- println "----- UseMultiClickTool() - Draw.lib --------";
- returnVal := MoveRelativeToWindow( pPointList ,, pSpecifier, 5);
-
- if (pDClickToEnd)
- begin # doubleClick to end sequence
- doubleClick;
- #LogStr("Double-clicked the mouse button to end drawing sequence");
- end;
- return(returnVal);
- end;
-
- #########################################################################
- # UseMultiClickDragTool(pPointList, pSpecifier, pDClickToEnd)
- #========================================================================
- # Author: David Matzner (x41220)
- # Description: mouseDown-drag-mouseUp-mouseDown-drag-mouseUp….
- # Parameters: pPointList - List of points to move to.
- # pSpecifier - Window specifier in which to drag in.
- # pDClickToEnd - Boolean flag indicating whether or not to double
- # click the mouse after dragging.
- # Returns: Nothing
- # Examples: UseMultiClickDragTool();
- # Assumptions: Mouse positioned at start point on entry. All points are
- # specified relative to window.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK UseMultiClickDragTool(pPointList, pSpecifier := 0, pDClickToEnd := 0)
- begin
- if (global gDebugFlag)
- println "----- UseMultiClickDragTool() - Draw.lib --------";
- oldMouseSpeed := mouseSpeed(4); # slow down mouse
- mouseDown := 4;
-
- for each pt in pPointList
- UseDragTool(pt, pSpecifier, mouseDown);
-
- mouseSpeed(oldMouseSpeed); # restore mouse speed
- if (pDClickToEnd)
- begin # doubleClick to end sequence
- doubleClick;
- #LogStr("Double-clicked the mouse button to end drawing sequence");
- end;
- end;
-
- #########################################################################
- # Object Structure Accessors()
- #========================================================================
- # Author: David Matzner (x41220)
- # Description: These functions access the data in an objectStruct data
- # structure.
- # Parameters: objectStruct
- # Returns: the requested data element or list
- #========================================================================
- # History:
- #
- #########################################################################
- ## objectStruct is the data structure that completely specifies the object to be drawn
- ## objectStruct {
- ## ElemStruct
- ## PointList
- ## Pattern
- ## Line
- ## Color
- ## }
-
- task GetElemStruct(objectStruct) begin return( objectStruct[1] ); end;
- task GetPointList(objectStruct) begin return( objectStruct[2] ); end;
- task GetPattern(objectStruct) begin return( objectStruct[3] ); end;
- task GetLine(objectStruct) begin return( objectStruct[4] ); end;
- task GetColor(objectStruct) begin return( objectStruct[5] ); end;
-
- task InsertElemStruct(tS, oS) begin return( replace( tS, 1, oS )); end;
- task InsertPointList(pts, oS) begin return( replace( pts, 2, oS )); end;
- task InsertPattern(pat, oS) begin return( replace( pat, 3, oS )); end;
- task InsertLine(lin, oS) begin return( replace( lin, 4, oS )); end;
- task InsertColor(col, oS) begin return( replace( col, 5, oS )); end;
-
-
- #########################################################################
- # MakePointList( pInset, pSpecifier, pNumPoints, pClosed, pVoidRect )
- #========================================================================
- # Author: David Matzner
- # Description: Generates a list of random points
- # Parameters: pInset - inset into window for ppoints to be generated.
- # pSpecifier - Window specifier for the window to generate points in.
- # pNumPoints - number of points to comprise the object
- # pClosed - 1 for closed object (first-last point the same)
- # 0 for open object (first-last point different)
- # pVoidRect - no points in object should be in this rectangle
- # Returns: List of Points.
- # Examples: theObject := MakePointList(rect); # 4 point closed object
- # theObject := MakePointList(theWindow.r, 4,1,thePalette.r);
- #========================================================================
- # History:
- #
- ########################################################################
- TASK MakePointList(pInset :={ 0,20,20,20 } , pSpecifier := 0, pNumPoints := global gNumPoints, pClosed := 0, pVoidRect := {} )
- begin
- if (global gDebugFlag)
- println "----- MakePointList() - Draw.lib --------";
- global gWindowInset, gVoidRect,gNumPoints, gBoundingRect;
- # To help assure drawing occurs in the content region
- if (gBoundingRect) # Window Rect
- boundingRect := gBoundingRect;
- else
- boundingRect := pSpecifier;
-
- if (gWindowInset) # Window inset
- pInset := gWindowInset;
- if (gVoidRect) # No points will be in this rect -
- pVoidRect := gVoidRect; # Coordinates should be relative to window
- pointList := GetRandomPointsRelativeToWindow(pInset, boundingRect,pNumPoints);
- if (pNumPoints = 1) # When only one set of point is required
- pointlist := { pointlist };
-
- # Last point is same as first
- if(pClosed)
- pointList := replace(pointList[1], pNumPoints, pointList );
-
- # only points that are not in the void rectangle
- if (pVoidRect)
- begin
- for x := 1 to (pNumPoints - pClosed) # last point will equal first if closed is true
- begin
- while (PtInRect(pointList[x],pVoidRect))
- begin
- thePointh := pointList[x][1];
- thePointv := pointList[x][2];
- if (global gDebugFlag)
- Println "{thePointh},{thePointv} is in the void rect - get another point";
- thePoint := GetRandomPointsRelativeToWindow(pInset, boundingRect);
- if (thePoint) pointList := replace(thePoint, x, pointList );
- else LogStr("GetRandomPointsRelativeToWindow() hosed");
- end;
- end;
- end;
-
- return( pointList );
- end; # MakePointList()
-
-
- #########################################################################
- # SetTool(pTool,pSelectTool, pObjectNumber)
- #========================================================================
- # Author: Kevin Avoy (x45604)
- # Description: This task takes a ToolStruct as a parameter. If the ToolStruct
- # evaluates to 'Random' a ToolStruct will be generated randomly.
- # If the pSelectTool evaluates to true the tool will also be selected.
- # Otherwise, the generated toolStruct will be returned without
- # selecting the tool.
- # Parameters: pTool - 0 - nothing done return 0
- # - Valid ToolStruct
- # - 'Random' - generates a random ToolStruct
- # pSelectTool - Boolean flag which indicates whether or not to
- # select the tool.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: 0 - nothing done 0 passed in.
- # Valid toolStruct
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SetTool(pTool := 'Random', pSelectTool := 1, pObjectNumber := 0)
- begin
- if (global gDebugFlag)
- begin
- Println "++++++++ SetTool() has just been called++++++++ ";
- Println "This is the toolStruct - ",pTool;
- end;
- global gToolList;
- if(pTool)
- begin
- if(pTool = 'Random')
- begin
- toolNum := Random(1,card(gToolList));
- pTool := gToolList[toolNum];
- #theObject := InsertElemStruct(pTool, theObject); # Insert the tool description
- if (global gDebugFlag)
- println " pTool after generating a random one in SetTool() - ", pTool;
- end;
- if (pSelectTool)
- begin
- PalettePicker(pTool,pObjectNumber);
- # This is where we put a hook for Dragging tools after selecting
- end;
- end;
- return(pTool);
- end;
-
- #########################################################################
- # GenerateObject(pTheObject)
- #========================================================================
- # Author: Kevin Avoy
- # Description: This task generates valid elements for any element that evaluates
- # to 'Random'.
- # Parameters: pTheObject - A complete Object Struct. The default is to
- # generate all elements of the returned object
- # randomly. Passing in partially completed object
- # struct will replace the elements which evaluate
- # to 'Random' with valid data.
- # Returns: pTheObject - a complete objectStruct no elements will evaluate
- # to 'Random'
- # Examples: GenerateObject({global PointerTool,'Random',0,'Random','Random'})
- # Assumptions: All the necessary Draw Structs have been defined correctly.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK GenerateObject(pTheObject := {'Random','Random','Random','Random','Random'})
- begin
- if (global gDebugFlag)
- Println "----- GenerateObject() - Draw.lib --------";
-
- theTool := GetElemStruct(pTheObject);
- if (theTool = 'Random')
- theTool := SetTool(theTool, 0);
- pTheObject := InsertElemStruct(theTool,pTheObject);
-
- thePointList := GetPointList(pTheObject);
- if (thePointList = 'Random')
- thePointList := SetPointList(pTheObject);
- pTheObject := InsertPointList(thePointList, pTheObject);
-
- thePattern := GetPattern(pTheObject);
- if (thePattern = 'Random')
- thePattern := SetPattern(thePattern, 0);
- pTheObject := InsertPattern(thePattern,pTheObject);
-
- theLine := GetLine(pTheObject);
- if (theline = 'Random')
- theLine := SetLine(theLine, 0);
- pTheObject := InsertLine(theLine,pTheObject);
-
- theColor := GetColor(pTheObject);
- if (theColor = 'Random')
- theColor := SetColor(theColor, 0);
- pTheObject := InsertColor(theColor,pTheObject);
-
- Return(pTheObject);
- end; # GenerateObject()
-
- #########################################################################
- # SetPointList(pTheObject, pSpecifier)
- #========================================================================
- # Author: Kevin Avoy (x45604)
- # Description: Determines the number of points required for a given tool type.
- # Then calls MakePointList() to generate pointlist for different
- # tool types.
- # kClick tools - require a single point.
- # kDrag tools - require a two points.
- # All multipoint tools - access the global gNumPoints to
- # determine the number of points.
- # Parameters: pTheObject - a complete objectStruct with atleast a valid
- # ToolStruct.
- # pSpecifier - Specifier of the window in which to generate
- # points in.
- # Returns: thePointList - a list of point within <pSpecifier>
- # Examples: SetPointList(TheObjectStruct, 0);
- # Assumptions: All the necessary Draw Structs have been defined correctly.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SetPointList(pTheObject, pSpecifier := 0)
- begin
- global gNumPoints;
- if (global gDebugFlag)
- Println "++++++++ SetPointList() has just been called++++++++ ";
- theTool := GetElemStruct(pTheObject);
- thePointList := GetPointList(pTheObject);
- if(theTool)
- begin
- if (thePointList)
- begin
- if(thePointList = 'Random')
- begin
- elemType := GetElemType(theTool);
- if(elemType)
- begin
- # Create a point list and insert into the object structure
- # The number of points depends on the tool
- elemType := GetElemType(theTool);
- if (elemType <= 3) numPoints := elemType; # Click - pointlist will be 1/drag - pointlist will be 2
- else numPoints := gNumPoints;
-
- thePointList := MakePointList(,pSpecifier,numPoints);
- end;
- else
- thePointList := 0;
- end;
- end;
- end;
- else
- println "Sorry, can't generate a pointlist unless a tool has been defined";
-
- return(thePointList);
- end; # SetPointList()
-
- #########################################################################
- # Draw(pTheTool, pThePointList, pThePattern, pTheLine, pTheColor, pSpecifier )
- #========================================================================
- # Author: Kevin Avoy
- # Description: This task provides a means for defining any of the elements
- # within an ObjectStruct and allowing the libraries to generate
- # any element that evaluates to 'Random' (default for all elements)
- # Parameters: 1 parameter for each of the elements of an objectStruct and
- # 1 additional parameter for the window pSpecifier.
- # pTheTool - ToolStruct
- # pThePointList - PointList (not user definable at this time)
- # pThePattern - PatternStruct
- # pTheLine - LineStruct
- # pTheColor - ColorStruct
- # pSpecifier - Window or rect to draw in
- # Returns: The actual ObjectStruct after generating 'Random' elements.
- # Examples: Draw(Global SelectTool, ‘Random’,0,0,{14,3, ‘Color’})
- # Assumptions: All the necessary Draw Structs have been defined correctly.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK Draw(pTheTool := 'Random', pThePointList := 'Random', pThePattern := 'Random', pTheLine := 'Random', pTheColor := 'Random', pSpecifier := 0)
- begin
- theObject := {'Random','Random','Random','Random','Random'};
-
- if not(pTheTool = 'Random')
- theObject := InsertElemStruct(pTheTool, theObject);
-
- #if not(pThePointList = 'Random') # We want to generate all pointlists for now KTA 7/92
- #theObject := InsertPointList(pThePointList, theObject);
-
- if not(pThePattern = 'Random')
- theObject := InsertPattern(pThePattern, theObject);
-
- if not(pTheLine = 'Random')
- theObject := InsertLine(pTheLine, theObject);
-
- if not(pTheColor = 'Random')
- theObject := InsertColor(pTheColor, theObject);
-
- theObject := DrawObject(theObject, pSpecifier);
- return(theObject);
- end;
-
- #########################################################################
- # SetColor(pTheColor, pSelectColor, pObjectNumber)
- #========================================================================
- # Author: Kevin Avoy
- # Description: This is used when selecting colors from a palette.This task
- # takes a ColorStruct as a parameter. If the ColorStruct evaluates
- # to 'Random' a ColorStruct will be generated randomly.
- # If the pSelectColor evaluates to true the color will also be selected.
- # Otherwise, the generated ColorStruct will be returned without
- # selecting the color.
- # Parameters: pTheColor - 0 - nothing done return 0
- # - Valid ColorStruct
- # - 'Random' - generates a random ColorStruct
- # pSelectColor - Boolean flag which indicates whether or not to
- # select the Color.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: colStruct - A valid ColorStruct
- # Examples: SetColor('Random', 1, 14);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SetColor(pTheColor := 'Random', pSelectColor := 1, pObjectNumber := 0)
- begin
- if (global gDebugFlag)
- begin
- Println "++++++++ SetColor() has just been called++++++++ ";
- Println "This is the colStruct - ",pTheColor;
- end;
- global gPaletteList, kColorPaletteNum;
- if (gPaletteList) and (kColorPaletteNum)
- begin
- if(pTheColor)
- begin
- if(pTheColor = 'Random') # Random Color
- begin
- thePalette := gPaletteList[kColorPaletteNum];
- pTheColor := GetRandomElement(thePalette);
- end;
- if (TypeOf(pTheColor) = 'integer')
- colStruct := { pTheColor, kColorPaletteNum, "Color"}; # create a struct to send to the palette picker
- else
- colStruct := pTheColor;
-
- if(colStruct) and (pSelectColor)
- PalettePicker(colStruct, pObjectNumber);
- end;
- else
- colStruct := 0;
- end;
- else
- begin
- colStruct := 0;
- if (global gDebugFlag)
- Println "Either the gPaletteList or the kColorPaletteNum is not defined";
- end;
- return(colStruct);
- end; # SetColor()
-
-
- #########################################################################
- # SetLine(pTheLine, pSelectLine, pObjectNumber)
- #========================================================================
- # Author: Kevin Avoy
- # Description: This is used when selecting line weights from a palette.
- # This task takes a LineStruct as a parameter. If the LineStruct
- # evaluates to 'Random' a LineStruct will be generated randomly.
- # If the pSelectLine evaluates to true the line will also be selected.
- # Otherwise, the generated LineStruct will be returned without
- # selecting the line weight.
- # Parameters: pTheLine - 0 - nothing done return 0
- # - Valid LineStruct
- # - 'Random' - generates a random LineStruct
- # pSelectLine - Boolean flag which indicates whether or not to
- # select the line.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: LineStruct - A valid LineStruct
- # Examples: SetLine('Random', 1, 14);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SetLine(pTheLine := 'Random', pSelectLine := 1, pObjectNumber := 0)
- begin
- if (global gDebugFlag)
- begin
- Println "++++++++ SetLine() has just been called +++++++++";
- Println "This is the LineStruct - ",pTheLine;
- end;
- global gPaletteList, kLinePaletteNum;
- if (gPaletteList) and (kLinePaletteNum)
- begin
- if(pTheLine)
- begin
- if(pTheLine = 'Random') # Random Line
- begin
- thePalette := gPaletteList[kLinePaletteNum];
- pTheLine := GetRandomElement(thePalette);
- end;
- if (TypeOf(pTheLine) = 'integer')
- LineStruct := { pTheLine, kLinePaletteNum, "Line"}; # create a struct to send to the palette picker
- else
- LineStruct := pTheLine;
-
- if(LineStruct) and (pSelectLine)
- PalettePicker(LineStruct, pObjectNumber);
- end;
- else
- LineStruct := 0;
- end;
- else
- begin
- LineStruct := 0;
- if (global gDebugFlag)
- Println "Either the gPaletteList or the kLinePaletteNum is not defined";
- end;
-
- return(LineStruct);
- end; # SetLine()
-
- #########################################################################
- # SetLine(pTheLine, pSelectLine, pObjectNumber)
- #========================================================================
- # Author: Kevin Avoy
- # Description: This is used when selecting line weights from menuItems.
- # This task takes a LineStruct as a parameter. If the LineStruct
- # evaluates to 'Random' a LineStruct will be generated randomly.
- # If the ppSelectLine evaluates to true the tool will also be selected.
- # Otherwise, the generated LineStruct will be returned without
- # selecting the line weight. This task depends upon a global
- # gLineWeights to be defined as the menuItem titles of the menuitems
- # which are used to set line wieghts.
- # Parameters: pTheLine - 0 - nothing done return 0
- # - Valid LineStruct
- # - 'Random' - generates a random LineStruct
- # pSelectLine - Boolean flag which indicates whether or not to
- # select the line.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: LineStruct - A valid LineStruct
- # Examples: SetLine('Random', 1, 14);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- # KTA 8/24/93 TCS stack parity check
- #########################################################################
- TASK SetLineMenuItems(pTheLine := {}, pSelectLine := 1, pObjectNumber := 0)
- begin
- failStr := '';
- if (global gDebugFlag)
- println "++++++++ SetLine() has just been called++++++++ ";
- global gLineWeights;
- if(pTheLine)
- begin
- # If a weight is not passed then calculate a random one
- if(pTheLine = 'Random') # Random Line wieght
- begin
- whichWeight := random(1, Card(gLineWeights)); # Calculate which random weight to use
- TheLineWeight := gLineWeights[whichWeight]; # Set variable to actual weight
- pTheLine := { TheLineWeight, "Menu Item", "Line"};
- #theObject := InsertLine(lineStruct, theObject);
- end;
- else
- TheLineWeight := pTheLine[1];
-
-
- if(TheLineWeight) and (pSelectLine)
- begin
- TCSStart({ 1, global kTCSetDraw },"SetLineMenuItems"); # Start TCS
- returnVal := SelectMenuItem(TheLineWeight); # Select it
- if (returnVal)
- returnVal := 1;
- else
- begin
- failStr := "Failed to select menu item for line weight";
- LogStr(failStr);
- end;
- TCSEnd({ 1, global kTCSetDraw },returnVal,failStr,pObjectNumber,TheLineWeight);
- end;
- end;
- else
- LogStr("Null object passed to SetLine");
- return(pTheLine);
- end; # SetLineMenuItems()
-
- #########################################################################
- # SetPattern(pThePattern, pSelectPattern, pObjectNumber)
- #========================================================================
- # Author: Kevin Avoy
- # Description: This is used when selecting patterns from a palette.
- # This task takes a PatternStruct as a parameter. If the PatternStruct
- # evaluates to 'Random' a PatternStruct will be generated randomly.
- # If the pSelectPattern evaluates to true the pattern will also be selected.
- # Otherwise, the generated PatternStruct will be returned without
- # selecting the pattern.
- # Parameters: pThePattern - 0 - nothing done return 0
- # - Valid PatternStruct
- # - 'Random' - generates a random PatternStruct
- # pSelectPattern - Boolean flag which indicates whether or not to
- # select the pattern.
- # pObjectNumber - Integer used to track all elements that make up
- # an object - TCS related.
- # Returns: patStruct - A valid PatternStruct
- # Examples: SetPattern('Random', 1, 14);
- # Assumptions: All draw related data structures set up properly.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK SetPattern(pThePattern := 'Random', pSelectPattern := 1, pObjectNumber := 0)
- begin
- if (global gDebugFlag)
- begin
- Println "++++++++ SetPattern() has just been called +++++++++";
- Println "This is the PatStruct - ",pThePattern;
- end;
- global gPaletteList, kPatternPaletteNum;
- if (gPaletteList) and (kPatternPaletteNum)
- begin
- if(pThePattern)
- begin
- if(pThePattern = 'Random') # Random pattern
- begin
- thePalette := gPaletteList[kPatternPaletteNum];
- pThePattern := GetRandomElement(thePalette);
- end;
- if (TypeOf(pThePattern) = 'integer')
- patStruct := { pThePattern, kPatternPaletteNum, "Pattern"}; # create a struct to send to the palette picker
- else
- patStruct := pThePattern;
-
- if(patStruct) and (pSelectPattern)
- PalettePicker(patStruct, pObjectNumber);
- end;
- else
- patStruct := 0;
- end;
- else
- begin
- patStruct := 0;
- if (global gDebugFlag)
- Println "Either the gPaletteList or the kPatternPaletteNum is not defined";
- end;
- return(patStruct);
- end; # SetPattern()
-
- #########################################################################
- # CheckSetup()
- #========================================================================
- # Author: Kevin Avoy
- # Description: Reports the current state of various draw related
- # globals and global structures. Call this task after a script
- # has defined all of its draw related globals. This routine will
- # print the current setting. A review of the output could help
- # to reveal any problems with the initial setup.
- # Parameters: none
- # Returns: nothing
- # Examples: CheckSetup();
- #========================================================================
- # History:
- #
- #########################################################################
- TASK CheckSetup()
- begin
- global kPalDocWind, kPalWind, kPullOffPal, kPopUpPal, kScrollPal;
-
- Println "The Bounding Rect is - ", global gBoundingRect; # Window inset
- Println "The Void Rect is - ", global gVoidRect; # Rect not to draw in - coordinates should be RelativeToWindow
- Println "The Number of point that all multipoint object will be drawn is - '{global gNumPoints}'";
- Println "The Global TextStr is - '{global gTextStr}'";
- For i := 1 to Card(global gPaletteList)
- begin
- CurrentPalette := gPaletteList[i];
- Println;
- if (CurrentPalette[2] = kPopUpPal)
- begin
- PopPoint := {CurrentPalette[1][1],CurrentPalette[1][2]};
- Println "•• Palette number - '{i}' is a popup Palette with a poppoint at ",PopPoint;
- TLFirstElem := {CurrentPalette[1][3],CurrentPalette[1][4]};
- Println "•• The TopLeft of first elem is ",TLFirstElem;
- if (Card(CurrentPalette[1]) = 4)
- Println "•• The popPoint and TopLeft coordinates are relative to the front window";
- else if (Card(CurrentPalette[1]) = 5)
- Println "•• The popPoint and TopLeft coordinates are absolute";
- Println "•• It is type - ",CurrentPalette[2], " which is a kPopUpPal ( pop up palette )";
- end;
- else if (CurrentPalette[2] = kPalWind)
- begin
- Println "•• Palette number - '{i}' has the specifier of - ",CurrentPalette[1][1];
- Println "•• It is type - ",CurrentPalette[2], " which is a kPalWind ( palette contained within its own window )";
- Println "•• The vertical distance between the top of the window and the top of the 1st tool is - ", CurrentPalette[1][2];
- end;
- else
- Println "•• Palette number - '{i}' has the Coordinates of - ",CurrentPalette[1];
-
- if (CurrentPalette[2] = kPalDocWind)
- Println "•• It is type - ",CurrentPalette[2], " which is a kPalDocWind ( contained within a documents window )";
- else if (CurrentPalette[2] = kPullOffPal)
- Println "•• It is type - ",CurrentPalette[2], " which is a kPullOffPal ( Pull off and then it is contained within its own window )";
- else if (CurrentPalette[2] = kScrollPal)
- Println "•• It is type - ",CurrentPalette[2], " which is a kScrollPal ( Scrolling Palette (we don't handle yet))";
-
- Println "•• The size of the Tool matrix is - ", CurrentPalette[3];
- Println "•• The Offset between tools is - ", CurrentPalette[4];
-
- Struct := { 1, i, "FirstItem"}; # create a struct to send to the palette picker
- PalettePicker(Struct);
- FinalTool := CurrentPalette[3][1] * CurrentPalette[3][2];
- Struct := { FinalTool, i, "LastItem"}; # create a struct to send to the palette picker
- PalettePicker(Struct);
- Println;
- end;
- global gToolList;
- end; # CheckSetup()
-